import API from '../../api/api.js'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    curId:"",
    screenHeight:app.globalData.screenHeight
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '回信',
    })
    this.data.curId = options.id
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },


  onEditorReady() {
    const that = this
    API.getDataById('xinjian',this.data.curId).then(res=>{
      let data = res[0]
      that.createSelectorQuery().select('#readonlyeditor').context(function (res) {
        that.editorCtx = res.context
        that.editorCtx.setContents({
          html: data.neiRong
        })
      }).exec()
      this.setData({
        data: res[0]
      })
    })
    
    
  },
  format:function(e) {
    let {
      name,
      value
    } = e.target.dataset
    if (!name) return
    this.editorCtx.format(name, value)

  },

  onReplyFunc:function(e){
    wx.setStorageSync('currPerson', e.currentTarget.dataset.value)
    wx.navigateTo({
      url: "/pages/xiexing/xiexing?mode=reply"
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let shareimages = app.globalData.shareimages
    let index = Math.floor(Math.random() * 5)
    return {
      title: '一个真正匿名的心情小程序',
      imageUrl: shareimages[index],
      path: '/pages/index/index'
    }
  },
  onShareTimeline: function () {
let shareimages = app.globalData.shareimages
    let index = Math.floor(Math.random() * 5)
    return {
      title: '一个真正匿名的心情小程序',
      imageUrl: shareimages[index]
    }
  }
})